package Smt.BaseDaoImp;

import Smt.BaseDao.BaseDao;
import Smt.BaseDao.SupplierDao;
import Smt.Util.Supplier;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class SupplierDaoImp implements SupplierDao {

	BaseDao bd = new BaseDao();
	private ResultSet rs;

	//账单的增删改
	public boolean util(String sql, Object[] u) {
		return bd.util(sql, u);
	}

	//账单的显示
	public ArrayList<Supplier> getSupplierList(Object[] o, String sql) {
		ArrayList<Supplier> list = new ArrayList<Supplier>();
		try {
			rs = bd.getList(sql, o);
			while (rs.next()) {
				try {
					Supplier s = new Supplier(rs.getInt("id"), rs.getString("name"), rs.getString("description"), rs.getString("atten"), rs.getString("tel"), rs.getString("adds"));
					list.add(s);
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			bd.closeAll();
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	//双条件数目查询
	public int SupplierCount(String name, String descriptionName) {
		String sql = "select count(*) from Supplier where name like '%" + name + "%' and description like '%" + descriptionName + "%'";
		return bd.Count(sql);
	}
}
